Skip to content

Potential fix for code scanning alert no. 1: Missing Dispose call on local IDisposable#21

Merged
seesharprun merged 1 commit intomainfrom
alert-autofix-1
Mar 19, 2026
Merged

Potential fix for code scanning alert no. 1: Missing Dispose call on local IDisposable#21
seesharprun merged 1 commit intomainfrom
alert-autofix-1

Conversation

@seesharprun
Copy link
Collaborator

Potential fix for https://github.com/AzureCosmosDB/samples/security/code-scanning/1

In general, the correct fix is to ensure that any object implementing IDisposable is disposed, preferably via a using statement/using declaration so that disposal happens automatically when the scope ends, even if exceptions occur. For a short, top-level sample like this, the most straightforward change is to wrap the CosmosClient creation in a using declaration so that it is disposed when the program reaches the end of the top-level scope.

Concretely, in dotnet/001-connect-passwordless/connect.cs, change the line that creates client from a plain var client = new CosmosClient(endpoint, credential); to a using var client = new CosmosClient(endpoint, credential);. This keeps all existing behavior the same while ensuring Dispose is called when the top-level statements complete. No additional methods or imports are required; using var is a C# language feature and CosmosClient already implements IDisposable.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…local IDisposable

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Sidney Andrews <sidandrews@microsoft.com>
@seesharprun seesharprun marked this pull request as ready for review March 19, 2026 14:58
Copilot AI review requested due to automatic review settings March 19, 2026 14:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the passwordless Cosmos DB connection sample to properly dispose the CosmosClient, addressing a code scanning alert about a missing Dispose call.

Changes:

  • Switches CosmosClient instantiation to a using declaration to ensure deterministic disposal.

@seesharprun seesharprun merged commit 05b5226 into main Mar 19, 2026
12 checks passed
@seesharprun seesharprun deleted the alert-autofix-1 branch March 19, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants